/**
 * 
 */
package ru.cargobroker.maip.contracts.cargo.domain;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToOne;
import javax.persistence.Transient;

import org.springframework.util.Assert;

import ru.cargobroker.maip.contracts.domain.InsObject;

/**
 * Cargo Insurance Object. Class for cargo specific properties of InsObject.
 * 
 * 
 * @author M.Frendiy
 * @since 0.0.1
 */
@Entity 
public class CargoInsObject extends InsObject {

	
	/**
	 * 
	 */
	private static final long serialVersionUID = -685192562030321811L;

	@OneToOne(cascade=CascadeType.ALL)
	@JoinColumn(name="OBJECT_ID")
	private CargoDetail cargoDetail;
	

	@Override
	public void setObjectName(String name) {
		super.setObjectName(name);
		if (cargoDetail != null) {
			cargoDetail.setObjectName(name);
		}
	}

	public CargoDetail getCargoDetail() {
		return cargoDetail;
	}

	public void setCargoDetail(CargoDetail cargoDetail) {
		Assert.notNull(cargoDetail);
		this.cargoDetail = cargoDetail;
		super.setObjectName(cargoDetail.getObjectName());
	}

}
